<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script>
        $(function(){
            $('#changePwdForm').on('submit',function(event){
                event.preventDefault();
                //判断两个密码是否一致
                if($('#oldpwd').val()==$('#newpwd').val()){
                    alert('新密码不能与旧密码一致!');
                    return;
                }
                $.ajax({
                    url:'/user/changePwd',
                    type:'post',
                    data:{
                        acc:sessionStorage.getItem('loginAcc'),
                        oldPwd:$('#oldpwd').val(),
                        newPwd:$('#newpwd').val()
                    },
                    success:function(data){
                        alert(data.message);
                        if(data.code==200){
                            //修改成功
                            sessionStorage.removeItem('loginAcc');
                            location.href='login.html';
                        }
                    }
                })
            })
        });
    </script>
</head>
<body>
    <form action="" method="post" id="changePwdForm">
        <label for="pwd">旧密码:</label>
        <input type="password" id="oldpwd" name="oldpwd" placeholder="请输入旧密码">
        <br/>
        <label for="rpwd">新密码:</label>
        <input type="password" id="newpwd" name="newpwd" placeholder="请输入新密码">
        <br/>
        <input type="submit">
    </form>
</body>
</html>